import { useEffect } from 'react'
import { Outlet, useNavigate } from 'react-router-dom'

import Header from '@/layouts/Header'
import { useAuthStore } from '@/store/AuthStore'

const Root = () => {
  const { uuid } = useAuthStore()
  const navigate = useNavigate()

  useEffect(() => {
    if (!uuid) {
      navigate('/login')
    } else {
      navigate('/')
    }
  }, [uuid, navigate])

  if (!uuid) {
    return <Outlet />
  }
  return (
    <>
      <Header />
      <Outlet />
    </>
  )
}

export default Root
